﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using Assist;
using YArchitech.Controls;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit.MEP.Opening.Properties;

namespace YArchitech.Revit.MEP.Opening
{
	public partial class OpeningSet : System.Windows.Forms.Form
	{
		public OpeningSet()
		{
			this.InitializeComponent();
			string filename = AssistFunc.GetAppRootPath() + "\\Data\\OpeningSet.xml";
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(filename);
				foreach (object obj in xmlDocument.SelectSingleNode("开洞设置"))
				{
					XmlNode xmlNode = (XmlNode)obj;
					if (!(xmlNode.Name == "协同方式"))
					{
						if (xmlNode.Name == "风管")
						{
							this.tbDuctWallD.Text = xmlNode.Attributes["WallD"].Value;
							this.tbDuctWallL.Text = xmlNode.Attributes["WallL"].Value;
							this.tbDuctWallR.Text = xmlNode.Attributes["WallR"].Value;
							this.tbDuctWallT.Text = xmlNode.Attributes["WallT"].Value;
							this.tbDuctWallB.Text = xmlNode.Attributes["WallB"].Value;
							this.tbDuctFloorD.Text = xmlNode.Attributes["FloorD"].Value;
							this.tbDuctFloorL.Text = xmlNode.Attributes["FloorL"].Value;
							this.tbDuctFloorR.Text = xmlNode.Attributes["FloorR"].Value;
							this.tbDuctFloorT.Text = xmlNode.Attributes["FloorT"].Value;
							this.tbDuctFloorB.Text = xmlNode.Attributes["FloorB"].Value;
							this.tbDuctBeamD.Text = xmlNode.Attributes["BeamD"].Value;
							this.tbDuctBeamL.Text = xmlNode.Attributes["BeamL"].Value;
							this.tbDuctBeamR.Text = xmlNode.Attributes["BeamR"].Value;
							this.tbDuctBeamT.Text = xmlNode.Attributes["BeamT"].Value;
							this.tbDuctBeamB.Text = xmlNode.Attributes["BeamB"].Value;
						}
						else if (xmlNode.Name == "水管")
						{
							this.tbPipeWallD.Text = xmlNode.Attributes["WallD"].Value;
							this.tbPipeFloorD.Text = xmlNode.Attributes["FloorD"].Value;
							this.tbPipeBeamD.Text = xmlNode.Attributes["BeamD"].Value;
						}
						else if (xmlNode.Name == "桥架")
						{
							this.tbBridgeWallL.Text = xmlNode.Attributes["WallL"].Value;
							this.tbBridgeWallR.Text = xmlNode.Attributes["WallR"].Value;
							this.tbBridgeWallT.Text = xmlNode.Attributes["WallT"].Value;
							this.tbBridgeWallB.Text = xmlNode.Attributes["WallB"].Value;
							this.tbBridgeFloorL.Text = xmlNode.Attributes["FloorL"].Value;
							this.tbBridgeFloorR.Text = xmlNode.Attributes["FloorR"].Value;
							this.tbBridgeFloorT.Text = xmlNode.Attributes["FloorT"].Value;
							this.tbBridgeFloorB.Text = xmlNode.Attributes["FloorB"].Value;
							this.tbBridgeBeamL.Text = xmlNode.Attributes["BeamL"].Value;
							this.tbBridgeBeamR.Text = xmlNode.Attributes["BeamR"].Value;
							this.tbBridgeBeamT.Text = xmlNode.Attributes["BeamT"].Value;
							this.tbBridgeBeamB.Text = xmlNode.Attributes["BeamB"].Value;
						}
						else if (xmlNode.Name == "套管")
						{
							bool @checked = Convert.ToBoolean(xmlNode.Attributes["CreateCasing"].Value);
							this.cbxCreate.Checked = @checked;
							int num = Convert.ToInt32(xmlNode.Attributes["CasingType"].Value);
							if (num == 1)
							{
								this.rbCasing1.Checked = true;
							}
							else if (num == 2)
							{
								this.rbCasing2.Checked = true;
							}
							else if (num == 3)
							{
								this.rbCasing3.Checked = true;
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void button1_Click(object sender, EventArgs e)
		{
			string filename = AssistFunc.GetAppRootPath() + "\\Data\\OpeningSet.xml";
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(filename);
				foreach (object obj in xmlDocument.SelectSingleNode("开洞设置"))
				{
					XmlNode xmlNode = (XmlNode)obj;
					if (!(xmlNode.Name == "协同方式"))
					{
						if (xmlNode.Name == "风管")
						{
							xmlNode.Attributes["WallD"].Value = this.tbDuctWallD.Text;
							xmlNode.Attributes["WallL"].Value = this.tbDuctWallL.Text;
							xmlNode.Attributes["WallR"].Value = this.tbDuctWallR.Text;
							xmlNode.Attributes["WallT"].Value = this.tbDuctWallT.Text;
							xmlNode.Attributes["WallB"].Value = this.tbDuctWallB.Text;
							xmlNode.Attributes["FloorD"].Value = this.tbDuctFloorD.Text;
							xmlNode.Attributes["FloorL"].Value = this.tbDuctFloorL.Text;
							xmlNode.Attributes["FloorR"].Value = this.tbDuctFloorR.Text;
							xmlNode.Attributes["FloorT"].Value = this.tbDuctFloorT.Text;
							xmlNode.Attributes["FloorB"].Value = this.tbDuctFloorB.Text;
							xmlNode.Attributes["BeamD"].Value = this.tbDuctBeamD.Text;
							xmlNode.Attributes["BeamL"].Value = this.tbDuctBeamL.Text;
							xmlNode.Attributes["BeamR"].Value = this.tbDuctBeamR.Text;
							xmlNode.Attributes["BeamT"].Value = this.tbDuctBeamT.Text;
							xmlNode.Attributes["BeamB"].Value = this.tbDuctBeamB.Text;
						}
						else if (xmlNode.Name == "水管")
						{
							xmlNode.Attributes["WallD"].Value = this.tbPipeWallD.Text;
							xmlNode.Attributes["FloorD"].Value = this.tbPipeFloorD.Text;
							xmlNode.Attributes["BeamD"].Value = this.tbPipeBeamD.Text;
						}
						else if (xmlNode.Name == "桥架")
						{
							xmlNode.Attributes["WallL"].Value = this.tbBridgeWallL.Text;
							xmlNode.Attributes["WallR"].Value = this.tbBridgeWallR.Text;
							xmlNode.Attributes["WallT"].Value = this.tbBridgeWallT.Text;
							xmlNode.Attributes["WallB"].Value = this.tbBridgeWallB.Text;
							xmlNode.Attributes["FloorL"].Value = this.tbBridgeFloorL.Text;
							xmlNode.Attributes["FloorR"].Value = this.tbBridgeFloorR.Text;
							xmlNode.Attributes["FloorT"].Value = this.tbBridgeFloorT.Text;
							xmlNode.Attributes["FloorB"].Value = this.tbBridgeFloorB.Text;
							xmlNode.Attributes["BeamL"].Value = this.tbBridgeBeamL.Text;
							xmlNode.Attributes["BeamR"].Value = this.tbBridgeBeamR.Text;
							xmlNode.Attributes["BeamT"].Value = this.tbBridgeBeamT.Text;
							xmlNode.Attributes["BeamB"].Value = this.tbBridgeBeamB.Text;
						}
						else if (xmlNode.Name == "套管")
						{
							xmlNode.Attributes["CreateCasing"].Value = this.cbxCreate.Checked.ToString();
							int num = 1;
							if (this.rbCasing1.Checked)
							{
								num = 1;
							}
							else if (this.rbCasing2.Checked)
							{
								num = 2;
							}
							else if (this.rbCasing3.Checked)
							{
								num = 3;
							}
							xmlNode.Attributes["CasingType"].Value = num.ToString();
						}
					}
				}
				xmlDocument.Save(filename);
			}
			catch
			{
			}
		}

		private void tbDuctWallB_TextChanged(object sender, EventArgs e)
		{
		}

		private void OpeningSet_Load(object sender, EventArgs e)
		{
		}
	}
}
